<?php
include("check.php");
include("check2.php");
include_once("../function.php");
include_once("../class/bonus_class.php");
include_once("../class/member_class.php");
include_once("../class/ulevel_class.php");
header("Content-Type: text/html;charset=utf-8");
session_start();
$us=getMemberbyID($_SESSION['ID']);
$_bonus_cl=new bonus_class();
if ($_POST['submit']){
	$member_cl=new member_class();
	$ulevel_cl=new ulevel_class();
    $_uil=$ulevel_cl->getulevelbyulevel(1);
    $mey=$_POST['mey'];
                        if($mey>0){
                            if($mey%$_uil['lsk']==0){
                                if($us['cfxf']>=$mey){
                                    $ulevelup['uid']=$_SESSION['ID'];
                                    $ulevelup['nickname']=$us['nickname'];
                                    $ulevelup['username']=$us['username'];
                                    $ulevelup['ylevel']=$sus['ulevel'];
                                    $ulevelup['uplevel']=$_POST['uplv'];
                                    $ulevelup['bdid']=$us['bdid'];
                                    $ulevelup['bdname']=$us['bdname'];
                                    $ulevelup['sid']=$sus['id'];
                                    $ulevelup['snickname']=$us['nickname'];
                                    $ulevelup['susername']=$us['username'];
                                    $ulevelup['udate']=now();
                                    $ulevelup['issh']=0;
                                    $ulevelup['cha']=$mey;
                                    add_insert_cl('ulevelup',$ulevelup);

                                    $us_update['lsk']=$us['lsk']+$mey;
                                    $us_update['cfxf']=$us['cfxf']-$mey;
                                    edit_update_cl('member',$us_update,$us['id']);
                                    $member_cl->addArea($us['id'],$us['treeplace'],$mey);
                                    $_bonus_cl->b3bonusd();
                                    $_bonus_cl->b0bonus();
                                    //$_bonus_cl->fwzx();
                                    echo "<script language=javascript>alert('复投完成.');window.location.href='?'</script>";
                                }else{
                                    echo "<script language=javascript>alert('您的创投基金余额不足.');window.location.href='?'</script>";
                                }
                            }else{
                                echo "<script language=javascript>alert('复投金额为".$_uil['lsk']."的倍数.');window.location.href='?'</script>";
                            }

                        }else{
                            echo "<script language=javascript>alert('请输入复投金额.');window.location.href='?'</script>";
                        }



}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/table.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="css/style.css" />
<title>升级申请</title>
<script language="javascript">
<!--
function checknickname(lx)
{
	var iframe = document.getElementById("iframe");
	var user =  document.getElementById("nickname");
	iframe.src= "checknickname.php?lx="+lx+"&nickname="+user.value;
}
-->
    function CheckForm() {
        mey=document.form1.mey.value;
        if(mey.length==0){
            alert("请输入复投金额");
        }
}
</script>
</head>
<body>
<iframe name="iframe" id="iframe" width="0" height="0" src="about:blank" style="display:none"></iframe>
<form name="form1" method="post" action="?" onSubmit="return CheckForm();">
<table  width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="table1">
	<tr>
  <td width="46%" align="right">创投基金余额:</td>
  <td  width="54%"><?=$us['cfxf']?></td>
  </tr>
  <tr>
  <td align="right">复投金额:</td>
  <td><input name="mey" id="mey" type="text">
  </tr>
</table>
<table align="center" class="ziti">
        <tr>
          <td><input name="submit" id="submit" type="submit" class="button_green" value="确定复投" onClick="javascript:return confirm('您确认复投吗？');"></td>
        </tr>
      </table>
<br>
<table width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="table1">
        <tr>
        <td height="20" colspan="8" align="center"> 申 请 记 录</td>
      </tr>
      <tr>
     	
        <td align="center">会员编号</td>
        <td align="center">会员姓名</td>
<!--        <td align="center">原级别</td>-->
<!--        <td align="center">申请级别</td>-->
        <td align="center">复投金额</td>
        <td align="center">申请时间</td>
        <td align="center">操作人编号</td>
      	<td align="center">操作人姓名</td>
        <td style="display:none" align="center">审核状态</td>
    </tr>
      <?php
	  	$pagesize = 10; //设置每页记录数 
	  	$sql = "SELECT * FROM `ulevelup` WHERE uid=".$_SESSION['ID']." or sid=".$_SESSION['ID']."";
		if($query = mysql_query($sql)){
	  		$sum = mysql_num_rows($query); //计算总记录数 
		}else{
			$sum=0;	
		} 
		if($sum % $pagesize == 0) //计算总页数 
			$total = (int)($sum/$pagesize); 
		else 
			$total = (int)($sum/$pagesize) + 1; 
			if (isset($_GET['page'])) //获得页码 
			{ 
				$p = (int)$_GET['page'];
			} 
			else 
			{ 
				$p = 1;
			}
			if ($p>$total){
				$p=$total;	
			}
		$start = $pagesize * ($p - 1); //计算起始记录 
      	$sql = "SELECT * FROM `ulevelup` WHERE uid=".$_SESSION['ID']." or sid=".$_SESSION['ID']." order by id desc limit ".$start.",".$pagesize;
		if($query = mysql_query($sql)){
		while ($row=mysql_fetch_array($query)){
			$yul=ulevel($row['ylevel']);
			$uul=ulevel($row['uplevel']);
	  ?>
      <tr>
        
        <td align="center"><?=$row['snickname']?></td>
        <td align="center"><?=$row['susername']?></td>
<!--        <td align="center"><?/*=$yul['lvname']*/?></td>
        <td align="center"><?/*=$uul['lvname']*/?></td>-->
        <td align="center"><?=$row['cha']?></td>
        <td align="center"><?=$row['udate']?></td>
        <td align="center"><?=$row['nickname']?></td>
        <td align="center"><?=$row['username']?></td>
        <td style="display:none"  align="center"><?php if ($row['issh']==1){?>通过审核<?php }else{?> <font color="#FF0000">未审核</font><?php }?></td>
      </tr>
      <?php
			}
		}
	  ?>
  </table>
  <table width="100%" border="0" class="ziti">
          <tr>
            <td align="left">&nbsp;</td>
            <td align="right"><?php echo fenye($p,$pagesize,$sum,$total,$cx)?></td>
          </tr>
        </table>
</form>
</body>
</html>